/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BookTransaction;

import Book.BookBean;
import Book.BookDetailsBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author mishra
 */
public class ReturnReport extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String Dfrom = request.getParameter("dfrom");
            String Dto = request.getParameter("dto");
            String fro[] = Dfrom.split("/");
            String dfrom = fro[1] + "/" + fro[0] + "/" + fro[2];
            String to[] = Dto.split("/");
            String dto = to[1] + "/" + to[0] + "/" + to[2];
            Vector<Object> list = BookTransaction.Query.ReturnReports(dfrom, dto);
            if(!list.isEmpty()){
            Iterator it = list.iterator();
            while (it.hasNext()) {
                BookTransBean btb = (BookTransBean) it.next();
                BookDetailsBean bdb = btb.getBookDetailsBean();
                BookBean bb = btb.getBookBean();

                out.println("<tr id='" + btb.getBookTransactionId() + "'>");
                out.println("<td><center>");
                out.println(btb.getEmployeeAddNo());
                out.println("</center></td>");
                out.println("<td><center>");
                out.println(btb.getBookNo());
                out.println("</center></td>");
                out.println("<td><center>");
                out.println(bb.getBookName());
                out.println("</center></td>");
                out.println("<td><center>");
                out.println(btb.getIssueDate());
                out.println("</center></td>");
                out.println("<td><center>");
                out.println(btb.getRetruningDate());
                out.println("</center></td>");
               out.println("<td><center>");
                    //String status = "";
                    if (btb.getUserType() == 2) {
                        out.println("<a href='#'><span class='label label-sucess' style='top: -6px;' onclick='StudentDetails("+btb.getEmployeeAddNo()+")'>Student</span></a>");
                        
                    } else if (btb.getUserType() == 1) {
                        String eCode=btb.getEmployeeAddNo().toString();
                        if(eCode.length()>3)
                        {
                       String code= eCode.substring(3,eCode.length());
                       out.println("<a href='#'><span class='label label-warning' style='top: -6px;' onclick='EmployeeDetails("+code+")'>Staff</span></a>");
                        }
                    } 
                out.println("</tr>");
            }
            }else{
                out.println("<tr>");
                out.println("<td colspan='3'>");
                out.println("<b>No Record Found</b>");
                out.println("</td>");
                out.println("</tr>");
            }
        } catch (Exception e) {
            out.println(e);
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
